/*   1:    */package com.linkage.bss.commons.util;
/*   2:    */
/*   3:    */import java.lang.reflect.Field;
/*   4:    */import java.lang.reflect.Method;
/*   5:    */import java.lang.reflect.Modifier;
/*   6:    */
/*  20:    */public class ClassUtil
/*  21:    */{
/*  22:    */  public static Object getClassInstance(String className)
/*  23:    */    throws ClassNotFoundException, IllegalAccessException, InstantiationException
/*  24:    */  {
/*  25: 25 */    Class clazz = getDefaultClassLoader().loadClass(className);
/*  26: 26 */    return clazz.newInstance();
/*  27:    */  }
/*  28:    */  
/*  38:    */  public static Method getMethod(Object obj, String methodName, Class... param)
/*  39:    */    throws NoSuchMethodException
/*  40:    */  {
/*  41: 41 */    return obj.getClass().getMethod(methodName, param);
/*  42:    */  }
/*  43:    */  
/*  47:    */  public static ClassLoader getDefaultClassLoader()
/*  48:    */  {
/*  49: 49 */    ClassLoader classLoader = null;
/*  50:    */    try {
/*  51: 51 */      classLoader = Thread.currentThread().getContextClassLoader();
/*  52:    */    }
/*  53:    */    catch (Throwable ex) {
/*  54: 54 */      return null;
/*  55:    */    }
/*  56: 56 */    if (classLoader == null) {
/*  57: 57 */      classLoader = ClassUtil.class.getClassLoader();
/*  58:    */    }
/*  59: 59 */    return classLoader;
/*  60:    */  }
/*  61:    */  
/*  62:    */  public static boolean hasMethod(Class clazz, String methodName, Class[] paramTypes) {
/*  63: 63 */    return getMethodIfAvailable(clazz, methodName, paramTypes) != null;
/*  64:    */  }
/*  65:    */  
/*  66:    */  public static Method getMethodIfAvailable(Class clazz, String methodName, Class[] paramTypes)
/*  67:    */  {
/*  68:    */    try
/*  69:    */    {
/*  70: 70 */      return clazz.getMethod(methodName, paramTypes);
/*  71:    */    }
/*  72:    */    catch (NoSuchMethodException ex) {}
/*  73: 73 */    return null;
/*  74:    */  }
/*  75:    */  
/*  83:    */  public static void setFieldValue(Object target, String fname, Class ftype, Object fvalue)
/*  84:    */  {
/*  85: 85 */    if ((target == null) || (fname == null) || ("".equals(fname)) || (
/*  86: 86 */      (fvalue != null) && (!ftype.isAssignableFrom(fvalue.getClass())))) {
/*  87: 87 */      return;
/*  88:    */    }
/*  89: 89 */    Class clazz = target.getClass();
/*  90:    */    try {
/*  91: 91 */      Method method = clazz.getDeclaredMethod(
/*  92: 92 */        "set" + Character.toUpperCase(fname.charAt(0)) + fname.substring(1), new Class[] { ftype });
/*  93: 93 */      if (!Modifier.isPublic(method.getModifiers())) {
/*  94: 94 */        method.setAccessible(true);
/*  95:    */      }
/*  96: 96 */      method.invoke(target, new Object[] { fvalue });
/*  97:    */    }
/*  98:    */    catch (Exception me) {
/*  99:    */      try {
/* 100:100 */        Field field = clazz.getDeclaredField(fname);
/* 101:101 */        if (!Modifier.isPublic(field.getModifiers())) {
/* 102:102 */          field.setAccessible(true);
/* 103:    */        }
/* 104:104 */        field.set(target, fvalue);
/* 105:    */      } catch (Exception fe) {
/* 106:106 */        fe.printStackTrace();
/* 107:    */      }
/* 108:    */    }
/* 109:    */  }
/* 110:    */}


/* Location:           E:\workspace\sungl111\workspace_promotion\BizHallConfig\WebRoot\WEB-INF\lib\bss.commons-0.1.jar
 * Qualified Name:     com.linkage.bss.commons.util.ClassUtil
 * JD-Core Version:    0.7.0-SNAPSHOT-20130630
 */